package com.yaozheng.vocationaltraining.dialog.ask;

import android.content.Context;
import android.view.Gravity;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.dialog.BaseDialog;
import com.yaozheng.vocationaltraining.fragment.BaseFragment;
import com.yaozheng.vocationaltraining.view.dialog.ConfirmCancelAskDialogView;
import com.yaozheng.vocationaltraining.view.dialog.ConfirmCancelAskDialogView_;

/**
 * 确定取消询问对话框
 */
public class ConfirmCancelAskDialog extends BaseDialog {
    ConfirmCancelAskDialogView confirmCancelAskDialogView;
    BaseFragment baseFragment;
    String runMethod;
    String cancelRunMethod;

    public ConfirmCancelAskDialog(Context context) {
        this(context, R.style.baseDialogStyleTheme, true, Gravity.CENTER, true);
    }

    public ConfirmCancelAskDialog(Context context, boolean backHide) {
        this(context, R.style.baseDialogStyleTheme, true, Gravity.CENTER, backHide);
    }

    public ConfirmCancelAskDialog(BaseFragment baseFragment) {
        this(baseFragment.getContext());
        this.baseFragment = baseFragment;
    }

    public ConfirmCancelAskDialog(Context context, int theme, boolean isCover, int gravity, boolean backHide) {
        super(context, theme, isCover, gravity, backHide);
    }

    public void setRunMethod(String runMethod) {
        this.runMethod = runMethod;
    }

    public void setCancelRunMethod(String cancelRunMethod) {
        this.cancelRunMethod = cancelRunMethod;
    }

    @Override
    public void setContentView() {
        confirmCancelAskDialogView = ConfirmCancelAskDialogView_.build(getContext());
        confirmCancelAskDialogView.setBaseDialogEventProcess(this);
        setContentView(confirmCancelAskDialogView);
    }

    /**
     * 设置标题并且内容
     *
     * @param title
     * @param content
     */
    public void setTitleAndroidContent(String title, String content) {
        confirmCancelAskDialogView.setTitleAndroidContent(title, content);
    }


    /**
     * 设置内容
     *
     * @param content
     */
    public void setContent(String content) {
        setContent(content, "请选择");
    }

    /**
     * 设置内容
     *
     * @param content
     */
    public void setContent(String content, String title) {
        confirmCancelAskDialogView.setTitleAndroidContent(title, content);
    }

    /**
     * 确定
     */
    public void baseCancel() {
        cancel();
        if (cancelRunMethod == null) {
            return;
        }
        if (baseFragment != null) {
            baseFragment.runMethod(cancelRunMethod);
        } else {
            if (baseActivity != null) {
                baseActivity.runMethod(cancelRunMethod);
            }
        }

    }

    /**
     * 确定
     */
    public void determine() {
        if (runMethod == null) {
            runMethod = "confirmCancelAskDialogDetermineClick";
        }
        cancel();
        if (baseFragment != null) {
            baseFragment.runMethod(runMethod);
        } else {
            if (baseActivity != null) {
                baseActivity.runMethod(runMethod);
            }
        }

    }
}
